﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DAL_NhaSach;
using BLL_NhaSach;

namespace AppQlyNhaSach.HoaDon
{
    public partial class frmCTHoaDon : DevExpress.XtraEditors.XtraForm
    {
        CTHoaDonBLL ctBLL;
        HoaDonBLL hdBLL;
        public frmCTHoaDon()
        {
            InitializeComponent();
        }

        private void frmCTHoaDon_FormClosing(object sender, FormClosingEventArgs e)
        {
            frmMainNS.isCTHoaDon = false;
        }

        private void frmCTHoaDon_Load(object sender, EventArgs e)
        {
            ctBLL = new CTHoaDonBLL(Properties.Settings.Default.ConnectionStringUser);
            hdBLL = new HoaDonBLL(Properties.Settings.Default.ConnectionStringUser);
            grdCTHoaDon.DataSource = ctBLL.getAllData();
            
        }

        private void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            try
            {
                int id = int.Parse(gridView1.GetFocusedRowCellValue("MaHD").ToString());
                DAL_NhaSach.HoaDon hds = (DAL_NhaSach.HoaDon)hdBLL.findObjects(id);
                txtMa.Text = hds.MaHD.ToString();
                txtNgay.Text = hds.NgayBan.ToShortDateString();
                txtNhanVien.Text = hds.NhanVien.HoTen;
                //DAL_NhaSach.ChiTietHoaDon ct = (DAL_NhaSach.ChiTietHoaDon)ctBLL.findObjects(hds.MaHD);
                txtDonGia.Text = gridView1.GetFocusedRowCellValue("DonGia").ToString();
                txtSoLuong.Text = gridView1.GetFocusedRowCellValue("SoLuong").ToString();
                txtTen.Text = gridView1.GetFocusedRowCellValue("TenSach").ToString();

            }
            catch { }
        }
    }
}